package org.example.kg_back.service.imp;

import org.example.kg_back.PoJo.DTO.LoginUserDetails;
import org.example.kg_back.PoJo.entity.SysUser;
import org.example.kg_back.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class UserDetailsServiceImpl implements UserDetailsService {
    @Autowired
    private SysUserMapper sysUserMapper;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        SysUser user = sysUserMapper.getByAccount(username);
        if (user == null){
            throw new RuntimeException("账号不存在");
        }
        return new LoginUserDetails(user);
    }
}
